﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace VS4CRM.Lib.Model
{
    /// <summary>
    /// Class incapsulates methods to work with customization files
    /// </summary>
    public class CustomizationFile
    {
        public string Path { get { return this.Info.FullName; } }
        public string Title { get { return System.IO.Path.GetFileNameWithoutExtension(this.Path); }}
        public bool IsXml { get { return this.Info.Extension.ToLower() == ".xml"; } }
        public bool IsZip { get { return this.Info.Extension.ToLower() == ".zip"; } }
        public bool Exists { get { return this.Info.Exists; } }

        private FileInfo Info { get; set; }
        
        #region IsEntity
        /// <summary>
        /// True if the customization file seems to be an entity customization in a predefined project structure
        /// </summary>
        public bool IsEntity 
        { 
            get { return this.Info.Directory.Name.ToLower() == Context.EntitiesDirectoty.ToLower(); }
        }
        #endregion

        #region IsExtension
        /// <summary>
        /// True if the customization file seems to be an extension file in predefined project structure
        /// </summary>
        public bool IsExtension
        {
            get { return this.Info.Directory.Name.ToLower() == Context.ExtensionsDirectory.ToLower(); }
        }
        #endregion

        #region IsSecurityRole
        /// <summary>
        /// True if the customization file seems to be a security role file in predefined project structure
        /// </summary>
        public bool IsSecurityRole
        {
            get { return this.Info.Directory.Name.ToLower() == Context.SecurityRolesDirectory.ToLower(); }
        }
        #endregion

        #region IsWorkflow
        /// <summary>
        /// True if the customization file seems to be a workflow file in predefined project structure
        /// </summary>
        public bool IsWorkflow
        {
            get { return this.Info.Directory.Name.ToLower() == Context.WorkflowsDirectory.ToLower(); }
        }
        #endregion
                
        // ===================== Methods ================================

        #region Construction
        /// <summary>
        /// Instantiates Customization file
        /// </summary>
        /// <param name="filePath">Path to the file needs to be analyzed</param>
        public CustomizationFile(string filePath) 
        {
            this.Info = new FileInfo(filePath);
        }
        #endregion
    }
}
